﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Metadata.Entity;

namespace T.FAS.Runtime.Metadata.SPI
{
    public abstract class AbsMetaDataManager : IMetaDataIdentifier, IMetaDataGenerateHandler
    {
        public Func<IMetaDataContent, bool> DefaultCheckFunc { get; set; }

        /// <summary>
        /// 校验元数据是否唯一
        /// </summary>
        /// <param name="metaDataContent">具体元数据</param>
        /// <returns>true: 唯一; false: 已存在</returns>
        public virtual bool CheckUnique(IMetaDataContent metaDataContent)
        {
            if (DefaultCheckFunc == null) return true;

            return DefaultCheckFunc(metaDataContent);
        }

        public Func<string, string, CommonResult> DefaultPersistenceFunc { get; set; }

        public abstract MetaGenerateCodeResult GenerateCode(IMetaDataContent metadata, bool isInternational);
        public virtual CommonResult Persistence(string fileName, string content) {
            if (DefaultPersistenceFunc == null) return new CommonResult();

            return DefaultPersistenceFunc(fileName, content);
        }
        
    }
}
